//
// Created by user on 2022/2/23.
//
#include <vector>
#include <unordered_set>
using namespace std;

vector<int> fairCandySwap(vector<int>& aliceSizes, vector<int>& bobSizes) {
    /*
     爱丽丝给 x 大小糖果给鲍勃，鲍勃给 y 大小糖果给爱丽丝
    sumA - x + y = sumB - y + x
    => x = y + (sumA - sumB) / 2

    对于 B 中任意 y，只要 A 中存在一个数 x，满足 x = y + (sumA - sumB) / 2
    那么 (x，y) 就是一个解
     *
     */

    int sumA = 0;
    for (int x:aliceSizes) sumA+=x;
    int sumB = 0;
    for (int x:bobSizes)sumB+=x;

    int delta = (sumA -sumB)/2;
    unordered_set<int> set;
    for (int num:aliceSizes)set.insert(num);

    vector<int> res(2);

    for (int y:bobSizes){
        int x = y+delta;
        if(set.count(x)){
            res[0] = x;
            res[1] = y;
            break;
        }
    }
    return res;
}